<?php

/**
 * Description of Helpers_CalendarCarousel
 *
 * @author a.novikov
 */
class Helpers_CalendarCarousel extends Helpers_Base {

	public function getViewPath() {
		return 'layouts/blocks/calendar_carousel.tpl';
	}

	public function calendarCarousel($year = 0, $month = 0, $day = 0) {
		$year = (int)$year;
		$month = (int)$month;
		$day = (int)$day;

		if (!$year) {
			$year = date('Y');
		}

		if (!$month) {
			$month = date('m');
		}
		
		if ($day) {
			$interval = '1 day';
			$this->view->common_date = $day;
		}
		else {
			$day = 1;
			$interval = '1 month';
		}
		
		$date = "'{$year}-{$month}-{$day}'";

		$peer = EventsPeer::getInstance();
		
		$select = $peer->select();

//		$start_at	= EventsPeer::START_AT;
		$startAt	= 'start_at';			// Костыль, по нормальному order не работает :(
		$endAt		= EventsPeer::END_AT;

		$select->where("{$endAt} >= $date");
		$select->where("{$startAt} < ($date + interval {$interval})");
		
		$select->order($startAt);
		
		//$slot = new Cache_Slot_Rowset($select, 3600);
		//$rowset = $slot->get();
		$rowset = $peer->fetchAll($select);

		EventsPeer::getInstance()->findParentRowset($rowset, 'type_id', null, array('cache' => array() ) );
		
		$this->view->events = ContentList::factoryByClassName('List_Event_Carousel', $rowset);
		
		return $this->render();
	}
}